<template>
    <!-- 设备异常上报 -->
     <el-container class="container">
        <!-- 头部导航 -->
        <el-header class="header">
            <el-header class="headerSon">
                <div>
                    <el-icon><Fold /></el-icon>
                    <span>设备管理</span>
                </div>
                <div>
                    <img :src="userPhoto" alt="">
                    <span>{{ userName }}</span>
                </div>
            </el-header>
        </el-header>
        <!-- 底部内容 -->
        <el-container class="content">
            <el-header>
                <!-- 搜索 -->
                <div>
                    <el-input
                        placeholder="设备编号"
                        v-model="getDeviveMangeListData.code"
                        style="width:185px;height: 25px;margin-right: 10px;"
                    ></el-input>
                    <el-input
                        placeholder="设备地点"
                        v-model="getDeviveMangeListData.address"
                        style="width:185px;height: 25px;margin-right: 10px;"
                    ></el-input>
                    <el-select placeholder="请选择设备运行状态" v-model="isStatus">
                        <el-option 
                        v-for="(item,index) in RunStateArr" 
                        :key="index" 
                        :value="item.value" 
                        :label="item.label"
                        >
                        </el-option>
                    </el-select>
                    <el-select placeholder="请选择设备状态" v-model="status">
                        <el-option 
                        v-for="(item,index) in StateArr" 
                        :key="index" 
                        :value="item.value" 
                        :label="item.label"
                        >
                        </el-option>
                    </el-select>
                    <el-select placeholder="请选择仓储状态" v-model="storageStatus">
                        <el-option 
                        v-for="(item,index) in StorageArr" 
                        :key="index" 
                        :value="item.value" 
                        :label="item.label"
                        >
                        </el-option>
                    </el-select>
                    <el-button type="primary" @click="goSearch">搜索</el-button>
                </div>
                <!-- 刷新 -->
                <div class="info">
                    <el-button type="danger" @click="goAdd('添加')"><el-icon><Plus /></el-icon>添加</el-button>
                    <el-button type="warning" style="width:80px;" @click="goRegularTime('定时重启')"><el-icon><Loading /></el-icon>定时重启</el-button>
                    <el-button type="info" @click="goInfo"><el-icon><Refresh /></el-icon>刷新</el-button>
                </div>
            </el-header>
            <el-footer>
                <el-table :data="ReportList" border style="width: 100%" >
                    <el-table-column label="设备编号" prop="code"></el-table-column>
                    <el-table-column label="设备名称" prop="name"></el-table-column>
                    <!-- <el-table-column label="设备版本号" prop="versionNumber"></el-table-column> -->
                    <el-table-column label="投放小区" prop="address"></el-table-column>
                    <el-table-column label="总回收量/kg" prop="totalWeight"></el-table-column>
                    <el-table-column label="当前回收量" prop="nowWeight"></el-table-column>
                    <el-table-column label="状态">
                        <template #default="scope">
                            <span :style="{color:scope.row.status == 0 ? 'green' : 'red'}">
                                {{ scope.row.status == 0 ? '正常' : '故障' }}、
                                {{ scope.row.storageStatus == 0 ? '未满仓' : '满仓' }}、
                                {{ scope.row.isStatus == 0 ? '离线' : '在线' }}
                            </span>
                        </template>
                    </el-table-column>
                    <el-table-column label="最后使用时间" prop="lastUseTime"></el-table-column>
                    <el-table-column label="备注" prop="remarks" width="120"></el-table-column>
                    <el-table-column label="操作">
                        <template #default="scope">
                            <el-button type="primary" @click="goEdit(scope.row,'编辑')">编辑</el-button>
                            <el-button type="warning" @click="goRestart(scope.row)">重启</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <!-- 分页器 -->
                <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-sizes="[15]"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total"
                    class="pagination"
                    background 
                />
            </el-footer>
        </el-container>
        <!-- 添加/编辑的模态框 -->
        <el-dialog v-model="Dialog" :modal="true" class="dialogOne">
            <template #header>
                <span>{{ flag }}</span>
            </template>
            <el-container>
                <el-form class="box" :model="opertaArr" :rules="rules" ref="myForm">
                    <el-row style="padding-left: 1em;">
                        <el-form-item label="组织机构" prop="companyId">
                            <el-select  placeholder="请选择" v-model="opertaArr.companyId">
                                <el-option
                                    v-for="item in CompanyList"
                                    :key="item.id"
                                    :value="item.id"
                                    :label="item.name"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-row>
                    <el-row v-if="flag== '编辑'">
                        <el-form-item label="持有人信息">
                            <el-input disabled v-model="phone"></el-input>
                        </el-form-item>
                        <el-form-item label="持有人姓名">
                            <el-input disabled v-model="realname"></el-input>
                        </el-form-item>
                    </el-row>
                    <el-row style="padding-left: 1em;">
                        <el-form-item label="销售电话" prop="salesPhone">
                            <el-input v-model="opertaArr.salesPhone"></el-input>
                        </el-form-item>
                        <el-form-item label="销售姓名" prop="salesName">
                            <el-input v-model="opertaArr.salesName"></el-input>
                        </el-form-item>
                    </el-row>
                    <el-row style="padding-left: 1em;">
                        <el-form-item label="设备名称" prop="name">
                            <el-input v-model="opertaArr.name"></el-input>
                        </el-form-item>
                        <el-form-item label="价格" style="box-sizing: border-box;padding-left: 2em;" prop="price">
                            <el-input v-model="opertaArr.price"></el-input><span style="font-size:12px;">元</span>
                        </el-form-item>
                    </el-row>
                    <el-row style="padding-left: 1em;">
                        <el-form-item label="设备编号" prop="code">
                            <el-input v-model="opertaArr.code"></el-input>
                        </el-form-item>
                        <el-form-item label="设备sn" style="box-sizing: border-box;padding-left: 1em;" prop="equipmentSn">
                            <el-input v-model="opertaArr.equipmentSn"></el-input>
                        </el-form-item>
                    </el-row>
                    <el-row style="padding-left: 1em;">
                        <el-form-item label="坐标拾取">
                            <span class="xy" @click="goPickUp">点击进入坐标拾取</span>
                        </el-form-item>
                        <el-form-item label="满仓阈值" prop="threshold">
                            <el-input v-model="opertaArr.threshold"></el-input>
                        </el-form-item>
                    </el-row>
                    <el-row style="padding-left: 3em;">
                        <el-form-item label="经度" style="width: 48%;" prop="longitude">
                            <el-input v-model="opertaArr.longitude"></el-input>
                        </el-form-item>
                        <el-form-item label="纬度" style="box-sizing: border-box;padding-left: 2em;width: 52%;" prop="latitude">
                            <el-input v-model="opertaArr.latitude"></el-input>
                        </el-form-item>
                    </el-row>
                    <el-row style="padding-left: 1em;">
                        <el-form-item label="位置描述" style="width:100%;" prop="address">
                            <el-input style="width:32%;" v-model="opertaArr.address"></el-input>
                        </el-form-item>
                    </el-row>
                    <el-row style="padding-left: 1em;">
                        <el-form-item label="设备状态"  style="width:50%;" prop="status">
                            <el-select  placeholder="请选择" v-model="opertaArr.status">
                                <el-option
                                    v-for="item in StateArr"
                                    :key="item.value"
                                    :value="item.value"
                                    :label="item.label"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="仓储状态" prop="storageStatus">
                            <el-select  placeholder="请选择" v-model="opertaArr.storageStatus">
                                <el-option
                                    v-for="item in StorageArr"
                                    :key="item.value"
                                    :value="item.value"
                                    :label="item.label"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-row>
                    <el-row style="padding-left: 1em;">
                        <el-form-item label="运清人员" class="note">
                            <el-select placeholder="请选择" style="width:100%;" multiple v-model="opertaArr.cleanList">
                                <el-option
                                    v-for="item in cleanerArr"
                                    :key="item.id"
                                    :value="item.id"
                                    :label="item.realname"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-row>
                    <el-row style="padding-left: 3em;">
                        <el-form-item label="备注" style="width:100%;">
                            <el-input type="textarea" v-model="opertaArr.remarks"></el-input>
                        </el-form-item>
                    </el-row>
                    <div class="close">
                        <el-button @click="goCancle">取消</el-button>
                        <el-button @click="goSureAdd(myForm)" type="primary" v-if="flag == '添加'">确定</el-button>
                        <el-button @click="goSureModify(myForm)" type="primary" v-if="flag == '编辑'">确定</el-button>
                    </div>
                </el-form>
            </el-container>
        </el-dialog>
        <!-- 定时启动/重启的模态框 -->
         <el-dialog v-model="RestartDialog" :modal="true" class="dialogOne dialogTwo">
            <template #header>
                <span>{{ RestartFlag }}</span>
            </template>
            <el-container>
                <el-form class="box" ref="RestartForm" :model="RestartArr" :rules="RestartRules" v-if="RestartFlag == '定时重启'">
                    <el-row>
                        <el-form-item label="重启时间" class="note" prop="date">
                            <el-col :span="11">
                                <el-date-picker
                                    v-model="RestartArr.date"
                                    placeholder="请选择重启时间"
                                    style="width: 100%"
                                    type="datetime"
                                    value-format="YYYY-MM-DD HH:mm:ss"
                                    :disabled-date="disabledDate" 
                                    :disabled-time="disabledTime"
                                />
                            </el-col>
                        </el-form-item>
                    </el-row>
                    <el-row>
                        <el-form-item label="应用设备" style="padding-left:1em;width:100%;" prop="name">
                            <el-radio-group v-model="RestartArr.name">
                                <el-radio name="names" :value="0">全部设备</el-radio>
                                <el-radio name="names" :value="1">应用部分设备</el-radio>
                                <el-radio name="names" :value="2">屏蔽部分设备</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-row>
                    <el-row>
                        <el-form-item label="选择设备" style="padding-left:1em;width:100%;" prop="device">
                            <el-select placeholder="设备编号" v-model="RestartArr.device" multiple>
                                <el-option
                                    v-for="item in device"
                                    :key="item.id"
                                    :value="item.id"
                                    :label="item.code"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-row>
                    <div class="close">
                        <el-button @click="RestartDialog = false">取消</el-button>
                        <el-button @click="goSureTwo(RestartForm)" type="primary">确定</el-button>
                    </div>
                </el-form>
            </el-container>
         </el-dialog>
     </el-container>
</template>

<script setup>
import { onMounted, reactive, ref } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus'
import { useRouter,useRoute } from 'vue-router';
import { 
    getDeviveMangeList,
    addDevice,
    getDeviceDetails,
    getAllCleaner,
    modifyDevice,
    getDevideCodeOrAddress,
    deviceScheduledRestart,
    onceDeviceRestart,
    getCompanyList
} from '@/components/DeviceMange/DeviceMange';
import { dayjs } from 'element-plus';
let router = useRouter()
let route = useRoute()
let userPhoto = ref("")//用户头像
let userName = ref("用户")//用户名/手机号
const currentPage = ref(1)
const pageSize = ref(15)
const total = ref(0)
let storageStatus = ref()//仓储状态
let StorageArr = ref([
    {value:0,label:'未满仓'},
    {value:1,label:'满仓'}
])
let isStatus = ref()//运行状态
let RunStateArr = ref([
    {value:0,label:'离线'},
    {value:1,label:'在线'}
])
let status = ref()//设备状态
let StateArr = ref([
    {value:0,label:'正常'},
    {value:1,label:'故障'}
])
let getDeviveMangeListData = ref({
    pageIndex:currentPage.value,
    pageSize:pageSize.value,
    code:'',//编号
    address:'',//地点
})
//调搜索框里面数据的接口
let ReportList = ref([])
let ReportFun = async (v) =>{//调数据设备管理的接口
    try{
        var res = null
        if(v){
            res = await getDeviveMangeList(v)
        }else{
            res = await getDeviveMangeList(getDeviveMangeListData.value)
        }
        if(res.code == 200){
            ReportList.value = res.dataset.dataset.list
            total.value = res.dataset.dataset.totalSize
        }
    }catch(error){
        console.log(error);
    }
}
//点击搜索
let goSearch = () => {
    if(storageStatus.value == 0 || storageStatus.value == 1){
        getDeviveMangeListData.value.storageStatus = storageStatus.value
    }
    if(isStatus.value == 0 || isStatus.value == 1){
        getDeviveMangeListData.value.isStatus = isStatus.value
    }
    if(status.value == 0 || status.value == 1){
        getDeviveMangeListData.value.status = status.value
    }
    ReportFun()
}
let goInfo = () => {//点击刷新
    location.reload()
}
//清运人员
let cleanerArr = ref([])//全部清运人员
let partcleanerArr = ref([])//部分清运人员
var longitude = route.query.longitude//经度
var latitude = route.query.latitude//纬度
let CompanyList = ref([])//组织机构数组
let opertaArr = ref({//详情或编辑中的数据//双向绑定的输入框中的数据(添加/编辑)
    companyId:'',//组织机构ID
    code:'',//设备编号
    name:'',//设备名称
    price:'',//价格
    threshold:'',//阈值double
    longitude: longitude, //经度double
    latitude: latitude,//纬度double
    address:'',//位置描述
    remarks:'',//备注
    salesName:'',//销售姓名
    salesPhone:'',//销售手机号
    equipmentSn:'',//设备sn
    storageStatus:'',//仓储状态
    status:'',//设备状态
    cleanList:[],//清运人员
})
let getAllCleanerFun = async () => {
    let getAllCleanerData = {
        pageIndex:1,
        pageSize:1000
    }
    try{
        const res = await getAllCleaner(getAllCleanerData)
        if(res.code == 200){
            cleanerArr.value = res.dataset.dataset.List
        }
    }catch(error){
        console.log(error);
    }
}
let mapFlag = ref(0)
let goPickUp = () => {//点击进入拾取坐标
    mapFlag.value = 0
    router.push({
        path:'/map',
        query:{
            mapFlag:mapFlag.value,
        }
    })
    if(opertaArr.value){
        sessionStorage.setItem('companyId',opertaArr.value.companyId ? opertaArr.value.companyId : '')
        sessionStorage.setItem('code',opertaArr.value.code)
        sessionStorage.setItem('name',opertaArr.value.name)
        sessionStorage.setItem('price',opertaArr.value.price)
        sessionStorage.setItem('threshold',opertaArr.value.threshold)
        sessionStorage.setItem('address',opertaArr.value.address)
        sessionStorage.setItem('remarks',opertaArr.value.remarks)
        sessionStorage.setItem('salesName',opertaArr.value.salesName)
        sessionStorage.setItem('salesPhone',opertaArr.value.salesPhone)
        sessionStorage.setItem('equipmentSn',opertaArr.value.equipmentSn)
        sessionStorage.setItem('storageStatus',opertaArr.value.storageStatus ? opertaArr.value.storageStatus : '')
        sessionStorage.setItem('status',opertaArr.value.status ? opertaArr.value.status : '')
        sessionStorage.setItem('cleanList',opertaArr.value.cleanList)
    }
}
let Dialog = ref(false)//模态框的开关(添加/编辑)
let flag = ref("")//点击的是详情还是编辑
let myForm = ref('')
// console.log(latitude,longitude);
const rules = reactive({
    companyId:[{required:true,message:'请选择组织机构',trigger:'blur'}],
    code:[{required:true,message:'请输入设备编号',trigger:'blur'}],
    name:[{required:true,message:'请输入设备名称',trigger:'blur'}],
    price:[{required:true,message:'请输入价格',trigger:'blur'}],
    threshold:[{required:true,message:'请输入阈值',trigger:'blur'}],
    longitude:[{required:true,message:'请输入经度',trigger:'blur'}],
    latitude:[{required:true,message:'请输入纬度',trigger:'blur'}],
    address:[{required:true,message:'请输入位置描述',trigger:'blur'}],
    salesName:[{required:true,message:'请输入销售姓名',trigger:'blur'}],
    salesPhone:[{required:true,message:'请输入销售手机号',trigger:'blur'}],
    equipmentSn:[{required:true,message:'请输入设备Sn',trigger:'blur'}],
    storageStatus:[{required:true,message:'请选择仓储状态',trigger:'blur'}],
    status:[{required:true,message:'请选择设备状态',trigger:'blur'}],
})
let goAdd = (v) => {//点击去添加
    Dialog.value = true
    flag.value = v
    opertaArr.value = {
        code:'',//设备编号
        name:'',//设备名称
        price:'',//价格
        threshold:'',//阈值double
        longitude: '', //经度double
        latitude: '',//纬度double
        address:'',//位置描述
        remarks:'',//备注
        salesName:'',//销售姓名
        salesPhone:'',//销售手机号
        equipmentSn:'',//设备sn
        storageStatus:'',//仓储状态
        status:'',//设备状态
    }
    sessionStorage.setItem('flag',v)
}
let id = ref('')//点击编辑时本条数据的id
let realname = ref('')//持有人姓名
let phone = ref('')//持有人手机号
let goEdit = async (row,v) => {//点击去编辑
    Dialog.value = true
    flag.value = v
    id.value = row.id
    sessionStorage.setItem('flag',v)
    let getDeviceDetailsData = {
        pageIndex:1,
        pageSize:1,
        id:row.id
    }
    try{
        const res = await getDeviceDetails(getDeviceDetailsData)
        if(res.code == 200){
            console.log(res);
            opertaArr.value = {
                companyId:Number(res.dataset.dataset.list.companyId),//组织机构
                code:res.dataset.dataset.list.code,//设备编号
                name:res.dataset.dataset.list.name,//设备名称
                price:res.dataset.dataset.list.price,//价格
                threshold:res.dataset.dataset.list.threshold,//阈值double
                longitude: res.dataset.dataset.list.longitude, //经度double
                latitude: res.dataset.dataset.list.latitude,//纬度double
                address:res.dataset.dataset.list.address,//位置描述
                remarks:res.dataset.dataset.list.remarks,//备注
                salesName:res.dataset.dataset.list.salesName,//销售姓名
                salesPhone:res.dataset.dataset.list.salesPhone,//销售手机号
                equipmentSn:res.dataset.dataset.list.equipmentSn,//设备sn
                storageStatus:res.dataset.dataset.list.storageStatus,//仓储状态
                status:res.dataset.dataset.list.status,//设备状态
                cleanList:res.dataset.dataset.list.cleanList,//清运人员
            }
            opertaArr.value.id = row.id
            partcleanerArr.value = res.dataset.dataset.list.cleanList
            realname.value = res.dataset.dataset.list.realname
            phone.value = res.dataset.dataset.list.phone
        }
    }catch(error){
        
    }
}
let goSureAdd = async (formEl) => {//添加模态框点击确定
    await formEl.validate(async valid => {
        if(valid){
            opertaArr.value.price = Number(opertaArr.value.price);
            opertaArr.value.threshold = Number(opertaArr.value.threshold);
            opertaArr.value.companyId = Number(opertaArr.value.companyId)
            // 调添加接口
            try{
                const res = await addDevice(opertaArr.value)
                if(res.code == 200){
                    ElMessage.success('设备添加成功')
                    ReportFun()
                }
            }catch(error){
                console.log(error);
            }
            Dialog.value = false
        }
    })
}
let goSureModify = async (formEl) => {//编辑模态框中的确定
    await formEl.validate(async valid => {
        if(valid){
            opertaArr.value.price = Number(opertaArr.value.price);
            opertaArr.value.threshold = Number(opertaArr.value.threshold);
            opertaArr.value.companyId = Number(opertaArr.value.companyId)
            //调编辑接口
            try{
                const res = await modifyDevice(opertaArr.value)
                if(res.code == 200){
                    ElMessage.success('编辑成功')
                    ReportFun()
                }
            }catch(error){
                console.log(error);
            }
            Dialog.value = false
        }
    })
}
//点击取消
let goCancle = () => {
    Dialog.value = false
    opertaArr.value = {//详情或编辑中的数据//双向绑定的输入框中的数据(添加/编辑)
        code:'',//设备编号
        name:'',//设备名称
        price:'',//价格
        versionNumber:'',//版本号int
        threshold:'',//阈值double
        longitude: '', //经度double
        latitude: '',//纬度double
        community:null,//设备小区
        address:'',//位置描述
        remarks:'',//备注
        salesName:'',//销售姓名
        salesPhone:'',//销售手机号
        equipmentSn:'',//设备sn
    }
}
let RestartDialog = ref(false)//定时重启/重启的模态框开关
let RestartFlag = ref("")//点击定时定时重启还是重启
let RestartArr = ref({//重启或定时重启中的数据//双向绑定的输入框中的数据
    date:"",//重启时间
    name:'',//应用设备
    device:[],//设备编号或设备地点
})
let RestartForm = ref("")
let RestartRules = reactive({
    date:[{required:true,message:"请选择重启时间",trigger:"blur"}],
    name:[{required:true,message:"请选择应用设备",trigger:"blur"}],
    device:[{required:true,message:"请选择设备",trigger:"blur"}]
})
let device = ref([])//点击添加设备时的设备地点或编号
let goRegularTime = async (v) => {//点击去定时重启
    RestartDialog.value = true
    RestartFlag.value = v 
    RestartArr.value = {
        date:"",//重启时间
        name:'',//应用设备
        device:"",//设备编号或设备地点
    }
    let getDevideCodeOrAddressData = {
        pageIndex:1,
        pageSize:1000
    }
    //调取获取设备编号或设备地点的接口
    try{
        const res = await getDevideCodeOrAddress(getDevideCodeOrAddressData)
        if(res.code == 200){
            device.value = res.dataset.dataset.List
        }
    }catch(error){
        console.log(error);
    }
}
let goSureTwo = async (formEl) => {//定时重启里面的点击确定
    await formEl.validate(async valid => {
        let deviceScheduledRestartData = {
            pageIndex:1,
            pageSize:1000,
            scheduledExecutionTime:RestartArr.value.date,
            applyType:RestartArr.value.name,
            instructionIds:RestartArr.value.device
        }
        if(valid){
            //调取重启接口
            console.log(deviceScheduledRestartData);
            const res = await deviceScheduledRestart(deviceScheduledRestartData)
            if(res.code == 200){
                ElMessage.success(res.dataset)
            }
            RestartDialog.value = false
        }
    })
}
let goRestart = (row) => {//点击去重启 
    let onceDeviceRestardData = {
        pageIndex:1,
        pageSize:1000,
        id:row.id
    }
    ElMessageBox.confirm(
        `确定要重启该设备的设备吗？`,
        '提示',
        {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
        }
    )
    .then(async () => {
        const res = await onceDeviceRestart(onceDeviceRestardData)
        if(res.code == 200){
            ElMessage({
                type: 'success',
                message: `${res.dataset}`,
            })
        }
    })
    .catch(() => {
        ElMessage({
            type: 'info',
            message: '取消重启',
        })
    })
}

//分页器
const size = ref('default')
const disabled = ref(false)
const handleSizeChange = (val) => {
    pageSize.value = val
    getDeviveMangeListData.value.pageSize = val; 
    ReportFun(getDeviveMangeListData.value)
  
}
const handleCurrentChange = (val) => {
    currentPage.value = val
    getDeviveMangeListData.value.pageIndex = val
    ReportFun(getDeviveMangeListData.value)
}
// 禁用过去的日期
const disabledDate = (time) => {
    // 只能选择今天及以后的日期
    return time < dayjs().startOf('day')
}

// 禁用当天过去的时间
const disabledTime = (date) => {
    // 如果选择的是今天，需要禁用过去的时间
    if (date && dayjs(date).isSame(dayjs(), 'day')) {
        const now = dayjs()
        return {
            disabledHours: () => {
                // 禁用当前小时之前的小时
                return Array.from({ length: now.hour() }, (_, i) => i)
            },
            disabledMinutes: (selectedHour) => {
                // 如果选中的是当前小时，禁用当前分钟之前的分钟
                if (selectedHour === now.hour()) {
                    return Array.from({ length: now.minute() }, (_, i) => i)
                }
                return []
            },
            disabledSeconds: (selectedHour, selectedMinute) => {
                // 如果选中的是当前小时和分钟，禁用当前秒之前的秒
                if (selectedHour === now.hour() && selectedMinute === now.minute()) {
                    return Array.from({ length: now.second() }, (_, i) => i)
                }
                return []
            }
        }
    }
    // 非今天则不禁用时间
    return {
        disabledHours: () => [],
        disabledMinutes: () => [],
        disabledSeconds: () => []
    }
}

//获取组织机构
const getCompanyListFun = async () => {
    let getCompanyListFunData = {
        pageIndex:1,
        pageSize:1000
    }
    try{
        const res = await getCompanyList(getCompanyListFunData)
        CompanyList.value = res.dataset.dataset.list
        // console.log(CompanyList.value);
    }catch(error){}
}
onMounted(() => {
    //页面已加载就调数据设备管理的接口
    ReportFun()
    const dialogOpen = sessionStorage.getItem('dialogOpen');
    if (dialogOpen === 'true') {
        Dialog.value = true; // 恢复打开状态
        flag.value = sessionStorage.getItem('flag') 
        opertaArr.value.companyId = sessionStorage.getItem('companyId') ? Number(sessionStorage.getItem('companyId')) : ''
        opertaArr.value.code = sessionStorage.getItem('code')
        opertaArr.value.name = sessionStorage.getItem('name')
        opertaArr.value.price = sessionStorage.getItem('price')
        opertaArr.value.threshold = sessionStorage.getItem('threshold')
        opertaArr.value.address = sessionStorage.getItem('address')
        opertaArr.value.remarks = sessionStorage.getItem('remarks')
        opertaArr.value.salesName = sessionStorage.getItem('salesName')
        opertaArr.value.salesPhone = sessionStorage.getItem('salesPhone')
        opertaArr.value.equipmentSn = sessionStorage.getItem('equipmentSn')
        opertaArr.value.storageStatus =sessionStorage.getItem('storageStatus') ? Number(sessionStorage.getItem('storageStatus')) : ''
        opertaArr.value.status =sessionStorage.getItem('status') ? Number(sessionStorage.getItem('status')) : ''
        opertaArr.value.cleanList = sessionStorage.getItem('cleanList')
    } else {
        Dialog.value = false; // 默认关闭
    }
    sessionStorage.removeItem('dialogOpen');
    getAllCleanerFun()
    getCompanyListFun()
})
</script>

<style lang="less" scoped>
.container{
    width:100%;
    height:100%;
    .header{
        background: #fff;
        height:80px;
        padding: 0;
        border-bottom: 1px solid  #ccc;
        box-shadow: 0px 1px 2px 0px #ccc;
        .headerSon{
            height:45px;
            display: flex;
            align-items: center;
            border-bottom: 1px solid #ccc;
            justify-content: space-between;
            div{
                display: flex;
                align-items: center;
                span{
                    display: inline-block;
                    padding:0px 10px;
                    font-size:13px;
                }
            }
        }
    }
    .content{
        width:100%;
        box-sizing: border-box;
        padding:20px;
        .el-header{
            width:100%;
            --el-header-padding: 0;
            :deep(.el-input__inner){
                font-size:12px;
            }
            .el-select{
                width:185px;
                margin-right:25px;
                :deep(.el-select__wrapper){
                    min-height: 25px;
                    span{
                        font-size:12px;
                    }
                    .el-select__placeholder{
                        transform: translateY(-53%);
                    }
                }
            }
            .el-button {
                height: 25px;
                font-size:12px;
                padding: 4px 10px;
            }
            .info{
                margin-top:10px;
                display: flex;
                justify-content: end;
                .el-button{
                    width:60px;
                }
            }
        }
        .el-footer {
            --el-footer-padding: 0;
            margin-top:5px;
            .el-table{
                :deep(.cell){
                    font-size:12px;
                    padding: 0 6px;
                }
                .el-button{
                    height: 23px;
                    font-size: 12px;
                    padding: 2px 10px;
                }
                :deep(.el-table__cell) {
                    padding: 3px 0;
                }
            }
        }
    }
}
:deep(.el-dialog__header){
    display: inline-block;
}
:deep(.dialogOne){
    color:#363638;
    border-radius:2px;
    --el-dialog-margin-top:6vh;
    min-width:800px;
    top:10%;
    .el-container{
        width:100%;
        font-size:12px;
        .box{
            width:100%;
            font-size:12px;
            .el-row{
                width:100%;
                margin-bottom: -5px; 
                .el-form-item{
                    width:50%;
                    .el-form-item__label:before{
                        content:''
                    }
                    .xy{
                        font-size: 12px;
                        color:#8ED170;
                    }
                    .el-form-item__label{
                        font-weight: 600;
                        font-size:12px;
                    }
                    .el-input__wrapper{
                        height:25px;
                    }
                    .el-select__wrapper {
                        min-height: 25px;
                        width:69%;
                    }
                    .el-input{
                        width:70%;
                    }
                    .el-textarea__inner{
                        width:100%;
                    }
                    .el-textarea__inner{
                        width:86%;
                    }
                }
                .note{
                    width:100%;
                    .el-select__wrapper{
                        width:86%;
                    }
                }
            }
            .close{
                width:100%;
                display: flex;
                justify-content: end;
                .el-button{
                    padding: 2px 10px;
                    font-size:12px;
                }
            }
        }
    }
}
:deep(.dialogTwo){
    top:50%;
    left:50%;
    transform: translate(-100%;-100%);
    .el-form-item__content{
        width:100px;
        .el-input__inner{
            font-size:12px;
        }
    }
    .el-radio__label{
        font-size:12px;
    }
    .el-select{
        width:100%;
        .el-select__wrapper{
            width:100% !important;
            span{
                font-size:12px;
            }
        }
    }
}
.demo-pagination-block + .demo-pagination-block {
  margin-top: 10px;
}
.demo-pagination-block .demonstration {
  margin-bottom: 16px;
}
.el-pagination{
    margin-top:5px;
    justify-content: end;
    box-sizing: border-box;
    padding-right:20px;
    font-size: 12px;
    --el-pagination-font-size: 12px;
    --el-pagination-button-width: 28px;
    --el-pagination-button-height: 28px;
    :deep(.el-select__wrapper){
        font-size: 12px;
        min-height: 25px;
    }
    :deep(.el-input__wrapper){
        height: 25px;
        font-size: 12px;
    }
}

</style>